package com.flong.lambda;

import org.junit.Test;

import java.util.Date;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @Author:liangjl
 * @Date: 2020/6/20-19:19
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
public class Test6 {

    @Test
    public void test1() {
        Date date = new Date();
        Supplier<Long> getTime = date::getTime;
        System.out.println(getTime.get());

    }

    /**
     * 类名::实例方法
     */
    @Test
    public void test2() {
        Function<String, Integer> f1 = (String str) -> {
            return str.length();
        };

        //类名::实例方法
        Function<String, Integer> f2 = String::length;
        Integer leg1 = f2.apply("周伯通");
        System.out.println(leg1);

        //使用方法引用进行截取
        BiFunction<String, Integer, String> bf1 = String::substring;
        String str1 = bf1.apply("hello world", 3);
        System.out.println(str1);

        //同等上面的方法引用
        //@param <T> the type of the first argument to the function
        //@param <U> the type of the second argument to the function
        //@param <R> the type of the result of the function
        BiFunction<String, Integer, String> bf2 = (String str,Integer index)->{
            return str.substring(index);
        };

        String str2 = bf2.apply("hello world", 3);
        System.out.println(str2);

    }


}
